package com.DosonLeung.homeschoolcommunication.Controllers;

import android.app.Activity;
import android.os.Bundle;
import android.os.Message;

import com.DosonLeung.homeschoolcommunication.Constant.UrlConstant;
import com.DosonLeung.homeschoolcommunication.Constant.UserConstant;
import com.DosonLeung.homeschoolcommunication.R;
import com.DosonLeung.homeschoolcommunication.Utils.NetWorkUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
 * Created by DosonLeuntg on 2014/11/16.
 */
public class TestActivity extends Activity {
    JSONArray jsonArray;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_activity);
        final String url = String.format(UrlConstant.getPersonUrl, "002","002");
        new Thread() {
            @Override
            public void run() {
                Message msg = new Message();
                try {
                    String otherPerson = NetWorkUtil.httpGet(url);
                    if(otherPerson!=null){
                        jsonArray = new JSONArray(otherPerson);
                        JSONObject jsonObject = jsonArray.getJSONObject(0);
                        JSONArray memberArray = jsonObject.getJSONArray("members");
                        HashMap<String,String> membersMap = new HashMap<String, String>();
                        int length = memberArray.length();
                        for(int i = 0; i < length; i++){
                            try {
                                jsonObject = memberArray.getJSONObject(i);
                                membersMap.put("uid",jsonObject.getString("uid"));
                                membersMap.put("name",jsonObject.getString("name"));
                                membersMap.put("avatar_path",jsonObject.getString("avatar_path"));
                                membersMap.put("sex",jsonObject.getString("sex"));
                                membersMap.put("phone",jsonObject.getString("phone"));
                                membersMap.put("role",jsonObject.getString("role"));
                                membersMap.put("contentType",jsonObject.getString("contentType"));
                                //membersMap.put("classid", UserConstant.CLASS_ID);
                                membersMap.put("description",jsonObject.getString("description"));
                                membersMap.put("lasttime","");
                                membersMap.put("lastnote","");
                                membersMap.put("lastnotetype","");
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                        msg.what = 0x200;
                    }else{
                        msg.what = 0x404;
                    }
                    //mHandler.sendMessage(msg);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
}
